DROP VIEW [dbo].[vi0115]
GO
CREATE VIEW [dbo].[vi0115] AS 
SELECT
	ID,
	ObjectID, ObjectName, DivisionID,
	S1, tb0050_S1.Sname as Sname1,
	S2, tb0050_S2.Sname as Sname2,
	S3, tb0050_S3.Sname as Sname3,
	tb0045.ObjectTypeID, ObjectTypeName,
	tb0045.Redays, tb0045.IsLockedOver,	
	IsSupplier, IsCustomer, IsUpdateName, 
	TradeName, LegalCapital, Address,
	CurrencyID,CountryID, CityID, PaymentID, 
	AreaID, RePaymentTermID, PaPaymentTermID,EmployeeID, 
	PaAccountID, ReAccountID,

	Tel, Fax, Email, Website, Note, BankName, Contactor,Contactor2,Mobile,Mobile2,
	BankAddress, BankAccountNo, 	LicenseNo,
	tb0045.Disabled, tb0045.CreateDate, tb0045.CreateUserID, tb0045.LastModifyDate, tb0045.LastModifyUserID, 
	VATNo, ReCreditLimit, PaCreditLimit, ReDueDays, PaDueDays, 
	PaDiscountDays, PaDiscountPercent, 

	O01ID, tb0033_O01.AnaName AS AnaName1,
	O02ID, tb0033_O02.AnaName AS AnaName2,
	O03ID, tb0033_O03.AnaName AS AnaName3,
	O04ID, tb0033_O04.AnaName AS AnaName4,
	O05ID, tb0033_O05.AnaName AS AnaName5,

	DeAddress, ReAddress, Note1,tb0045.GroupShow
   

From tb0045 	Left Join tb0044 On tb0045.ObjectTypeID = tb0044.ObjectTypeID

		Left Join tb0050 tb0050_S1 On tb0045.S1= tb0050_S1.S and tb0050_S1.STypeID ='O01' 
		Left Join tb0050 tb0050_S2 On tb0045.S2= tb0050_S2.S and tb0050_S2.STypeID ='O02' 
		Left Join tb0050 tb0050_S3 On tb0045.S3= tb0050_S3.S and tb0050_S3.STypeID ='O03' 
		Left Join tb0033 tb0033_O01 On tb0045.O01ID= tb0033_O01.AnaID and tb0033_O01.AnaTypeID ='O01' 
		Left Join tb0033 tb0033_O02 On tb0045.O02ID= tb0033_O02.AnaID and tb0033_O02.AnaTypeID ='O02' 
		Left Join tb0033 tb0033_O03 On tb0045.O03ID= tb0033_O03.AnaID and tb0033_O03.AnaTypeID ='O03' 
		Left Join tb0033 tb0033_O04 On tb0045.O04ID= tb0033_O04.AnaID and tb0033_O04.AnaTypeID ='O04' 
		Left Join tb0033 tb0033_O05 On tb0045.O05ID= tb0033_O05.AnaID and tb0033_O05.AnaTypeID ='O05'

GO